<html>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>添加打包软件</title>
    <head>
        <link href="resources/styles/cms.css" rel="stylesheet" type="text/css">
        <script language="JavaScript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
        <script language="JavaScript" src="resources/js/jquery.form.js"></script>
        <script language="javascript">
            (function(){
                $('form').ajaxForm({
					dataType: 'json',
                    beforeSend: function(){
						$('#loading_img').show();
					   	return true;
                    },
                    success: function(data){
						var status = data.status;
						if(status == 2){
							alert('渠道号错误');
						}else if(status == 3){
							alert('该渠道不允许修改');
						}else if(status == 4){
							alert('必须填写绑定的内部包名');
						}else if(status == 5){
							$('#loading_img').hide();
							alert('更新跳转地址成功');
						}else if(status == 1){
							//$('#form_save').remove();
							$('#loading_img').hide();
							$('#coo_url').html('');
							for(var j=0;j<data.coo_url.length;j++){
								$('#coo_url').append(data.coo_url[j]+"\n");
							}
						}
                    },
                    complete: function(xhr){
                        
                    }
                });
            })();
			function add_software(){
				var add_soft_str = '<span style="float:left;clear:both;">&nbsp;&nbsp;软件内部包名：<input name="bind_package[]" />&nbsp;<input type="button" value = "删除软件" onclick="javascript:del_software(this)" /></span>';
				$('#package_span').append(add_soft_str);
			}
			function del_software(obj){
				var input_val = $(obj).prev("input").val(); 
				if(input_val.length > 0){
					if(confirm('确定？')){
						$(obj).parent().remove();
					}
				}else{
					$(obj).parent().remove();
				}
			}
			
			function rsync(obj){
				var channel_id = $('#channel_id').val();
				if(channel_id == '' || channel_id.length <= 0){
					alert('请先保存该渠道,或者该渠道不需要同步');
					return false;
				}
				$.ajax({
   					type: "POST",
   					url: "<{$domain}>?act=package.rsync",
   					data: "channel_id="+channel_id,
					dataType: "json",
					beforeSend: function(){
						$(obj).remove();
						$('#rsyncing').html('同步中...');
					},
   					success: function(msg){
     					if(msg.status == 2){
							alert('渠道号不正确');
						}else if(msg.status == 3){
							alert('该渠道不属于该用户');
						}else if(msg.status == 4){
							alert('该渠道不需要同步');
						}else if(msg.status == 1){
							alert('同步成功');
							$('#rsyncing').html('同步完成');
						}
   					}
				}); 
			}
			
			function writeObj(obj){
	    		var description = "";
	    		for(var i in obj){ 
	        		var property=obj[i]; 
	        		description+=i+" = "+property+"\n";
	    		} 
	    		alert(description);
			}
			
        </script>
        <style type="text/css">
            body {
                background-image: url(resources/images/tab_shadow.gif);
                background-attachment: fixed;
                background-repeat: repeat-x;
            }
        </style>
    </head>
    <body>
        <form action="<{$domain}>?act=package.doupdate" method="post" name="packageform">
            <table width="100%" border=0 align="center" cellPadding=2 cellSpacing=1 class=color-tabletrim>
                <tr>
                    <td height="20" class="j">
                        <img src="resources/images/file.gif" width="14" height="14" border="0" align="absmiddle" />&nbsp;&nbsp;添加渠道包
                    </td>
                </tr>
                <tr class="e">
                    <td nowrap="nowrap" height="20">
                        <table width="100%" border="0" cellpadding="2" cellspacing="0">
                        	<tr>
                                <td align="right" width="100" class="c_lick">打包渠道号：</td>
                                <td class="c_lick" bgColor="#f8f8f8">
                                    <input type="text" name="channel_id" value="<{$out.channel_list_info.channel_id}>" readonly />
                                </td>
                            </tr>
                        	<tr>
                                <td align="right" width="100" class="c_lick">渠道自定义标识：</td>
                                <td class="c_lick" bgColor="#f8f8f8">
                                    <input type="text" name="channel_coo" value="<{$out.channel_list_info.channel_coo}>" />
                                </td>
                            </tr>
							<{if $out.channel_list_info.is_bind eq 1}>
                            <tr>
                                <td align="right" class="c_lick">选项：</td>
                                <td class="c_lick" bgColor="#f8f8f8">
                                	
									<table width="100%" border="0" cellpadding="2" cellspacing="0">
									<tr>
										<td align="left" width="10%" class="c_lick">
                                    	捆绑其他软件：
										</td>
										<td class="c_lick" algin="left" bgColor="#f8f8f8">
											<div id="package_span">
											<{section name=channel_url loop=$out.channel_url_info}>
											<span style="float:left;clear:both;">&nbsp;&nbsp;软件内部包名：<input name="bind_package[]" value="<{$out.channel_url_info[channel_url].package_name}>" />
											<{if $smarty.section.channel_url.first}>
											<input type="button" value = "添加软件" onclick="javascript:add_software()" />
											<{else}>
											<input type="button" value = "删除软件" onclick="javascript:del_software(this)" />
											<{/if}>
											</span>
											<{sectionelse}>
											<span style="float:left;clear:both;">&nbsp;&nbsp;软件内部包名：<input name="bind_package[]" />&nbsp;<input type="button" value = "添加软件" onclick="javascript:add_software()" /></span>
											<{/section}>
											</div>
										</td>
                                    </tr>
									</table>
                                </td>
                            </tr>
							<{/if}>
                            <tr>
                                <td align="right" class="c_lick">下载地址：</td>
                                <td class="c_lick" bgColor="#f8f8f8">
                                    <input type="text" name="download_url" size=50 value="<{if $out.channel_list_info.is_download_url eq 1}><{$out.channel_url_info[0].download_url}><{/if}>" />
                                    <font color="red">
                                        &nbsp;* 填写以后该渠道会直接访问本地址
                                    </font>
                                </td>
                            </tr>
                            <tr id="form_save">
                                <td class="c_lick" height="20" colspan="2">
                                    <input class=button type="submit" value="修改"><span id="loading_img" style="display:none;">&nbsp;&nbsp;&nbsp;&nbsp;<img src="resources/images/loading.gif" /></span>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </TABLE>
        </form>
		
		<table width="100%" border="0" cellpadding="2" cellspacing="0">
        	<tr>
            	<td align="right" width="100" class="c_lick">推广地址：</td>
                <td class="c_lick" style="bgColor:#f8f8f8;text-align:left;">
                <textarea id="coo_url" rows="10" cols="90"><{section name=channel_url_info loop=$out.channel_url_info}><{$out.channel_url_info[channel_url_info].coo_url}>
<{/section}></textarea>
                </td>
        	</tr>
			<tr>
            	<td align="right" width="100" class="c_lick">同步源文件：</td>
                <td class="c_lick" style="bgColor:#f8f8f8;text-align:left;">
				<input id="channel_id" type="hidden" name="channel_id_button" value="<{$out.channel_list_info.channel_id}>" />
                <input type="button" value="同步到本地服务器" onclick="javascript:rsync(this)" /><span id="rsyncing"></span>(该操作会引导文件在本地服务器下载，比如台湾)
                </td>
        	</tr>
		</table>
		
    </body>
</html>